﻿using IDAL;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;

namespace DAL
{
    public class UserDAL<T>:IBaseDAL<T> where T : class
    {
        MYDbContext db;
        public UserDAL(MYDbContext db)
        {
            this.db = db;
        }

        public async Task<int> GetAdd(T t)
        {
            await db.Set<T>().AddAsync(t);
            return await db.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public async Task<int> GetUpdate(T t)
        {
             db.Set<T>().Update(t);
            return await db.SaveChangesAsync();
        }

        public async Task<T> GetValue(Expression<Func<T, bool>> exp)
        {
            return await db.Set<T>().Where(exp).FirstOrDefaultAsync();
        }
    }
}
